package com.atnjupt.Servlet;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author Wizarder
 * @create 2021-06-15 12:36
 */
public class LoginServlet extends HttpServlet {

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //获取表单的参数
        String username = req.getParameter("username");
        String password = req.getParameter("password");
        resp.setContentType("text/html;charset=UTF-8");
        if ("luhu123".equals(username) && "admin".equals(password)){
            req.getSession().setAttribute("user",username);
            resp.getWriter().write("登陆成功");
        }else{
            req.getRequestDispatcher("/login.jsp").forward(req,resp);
        }

    }
}
